﻿using System;
using System.Collections;

namespace ExFlash.Tags
{
    public class FileAttributesTag : Tag
    {
        private const int FileAttributesTagSize = 4;
        
        protected const int UseDirectBlitIndex = 1;
        protected const int UseGPUIndex = 2;
        protected const int HasMetaDataIndex = 3;
        protected const int ActionScript3Index = 4;
        protected const int UseNetworkIndex = 7;

        private readonly BitArray _flags;

        public Boolean UseDirectBlit
        {
            get
            {
                return _flags[UseDirectBlitIndex];
            }
            private set
            {
                _flags[UseDirectBlitIndex] = value;
            }
        }

        public Boolean UseGPU
        {
            get
            {
                return _flags[UseGPUIndex];
            }
            private set
            {
                _flags[UseGPUIndex] = value;
            }
        }

        public Boolean HasMetaData
        {
            get
            {
                return _flags[HasMetaDataIndex];
            }
            private set
            {
                _flags[HasMetaDataIndex] = value;
            }
        }

        public Boolean ActionScript3
        {
            get
            {
                return _flags[ActionScript3Index];
            }
            private set
            {
                _flags[ActionScript3Index] = value;
            }
        }

        public Boolean UseNetwork
        {
            get
            {
                return _flags[UseNetworkIndex];
            }
            private set
            {
                _flags[UseNetworkIndex] = value;
            }
        }

        public FileAttributesTag(Int32 offset)
            : base(TagCodes.FileAttributes, FileAttributesTagSize,offset)
        {
            _flags = new BitArray(32);
        }

        public override void SwfDeserialize(BinaryBitReader reader)
        {
            reader.SkipBits(UseDirectBlitIndex);
            UseDirectBlit = reader.ReadBoolean();
            UseGPU = reader.ReadBoolean();
            HasMetaData = reader.ReadBoolean();
            ActionScript3 = reader.ReadBoolean();
            reader.SkipBits(2);
            UseNetwork = reader.ReadBoolean();
            reader.SkipBits(24);
            reader.AlignBits();
        }

        public override void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }
    }
}
